/*
 * @lc app=leetcode.cn id=541 lang=javascript
 *
 * [541] 反转字符串 II
 */

// @lc code=start
/**
 * @param {string} s
 * @param {number} k
 * @return {string}
 */
var reverseStr = function(s, k) {
    let falg = 0
    let str = ''
    let res = ''
    for (let index = 0; index < s.length; index++) {
        const element = s[index];
        if (falg < k) {
            falg++
            str = element + str
        } else if (falg < (2 * k)) {
            falg++
            str += element
        } else {
            res += str
            str = element
            falg = 1
        }
    }
    return res += str
};
// @lc code=end

